package com.czk.yygh.user.controller.api;

import com.czk.model.user.Patient;
import com.czk.yygh.common.result.Result;
import com.czk.yygh.common.utils.AuthContextHolder;
import com.czk.yygh.user.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 就诊人接口管理
 *
 * @Author:ChenZhangKun
 * @Date: 2021/11/25 20:46
 */
@Api(tags = "就诊人管理")
@RestController
@RequestMapping("/api/user/patient")
public class PatientApiController {
    @Autowired
    private PatientService patientService;

    @GetMapping("/auth/findAll")
    @ApiOperation(value = "查看就诊人")
    public Result findAll1(HttpServletRequest request) {
        Long userId = AuthContextHolder.getUserId(request);
        List<Patient> list = patientService.findAllByUserId(userId);
        return Result.ok(list);
    }

    @PostMapping("/auth/save")
    @ApiOperation(value = "添加就诊人")
    public Result savePatient(@RequestBody Patient patient, HttpServletRequest request) {
        Long userId = AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        patientService.save(patient);
        return Result.ok();
    }

    @GetMapping("/auth/get/{id}")
    @ApiOperation(value = "通过id获取就诊人信息")
    public Result getPatient(@PathVariable Long id) {
        Patient patient = patientService.getPatient(id);
        return Result.ok(patient);
    }

    @GetMapping("/auth/update")
    @ApiOperation(value = "更新就诊人信息")
    public Result updatePatient(@RequestBody Patient patient) {
        patientService.updateById(patient);
        return Result.ok();
    }

    @DeleteMapping("/auth/remove/{id}")
    @ApiOperation(value = "移除就诊人")
    public Result removePatient(@PathVariable Long id) {
        patientService.removeById(id);
        return Result.ok();
    }

    /**
     * 订单接口远程获取就诊人信息
     *
     * @param id
     * @return
     */
    @GetMapping("/inner/get/{id}")
    public Patient getPatientOrder(@PathVariable Long id) {
        Patient patient = patientService.getPatient(id);
        return patient;
    }
}
